package com.pearl.jacksoncore.demo.mixin;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.util.BeanUtil;
import com.fasterxml.jackson.datatype.my.TokenInfo;

import java.util.Date;

/**
 * @author TD
 * @version 1.0
 * @date 2024/4/10
 */
public class MixinTest {
    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();

        // 关联
        objectMapper.addMixIn(TokenInfo.class,MixinTokenInfo.class);

        // 模拟第三包返回令牌对象
        TokenInfo tokenInfo=new TokenInfo();
        tokenInfo.setUsername("王法");
        tokenInfo.setBirthday(new Date());
        tokenInfo.setPassword("123456");

/*        // 转换为对应格式的VO
        TokenInfoVO vo=new TokenInfoVO();
        vo.setUsername(tokenInfo.getUsername());
        vo.setBirthday(tokenInfo.getBirthday());*/

        // 序列化  ObjectMapper#addMixIn
/*        String value = objectMapper.writeValueAsString(vo);
        System.out.println(value);*/


        // 序列化
        String value = objectMapper.writeValueAsString(tokenInfo);
        System.out.println(value);

    }
}
